package cn.itcast.mq.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * topic 通过routingkey中topic格式的key判断由交换机将数据给对应的队列
 */
@Component
public class ConsumerTopicAmqpTest {

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "simple.queue1"),
            exchange = @Exchange(name = "exchange.topic",type = ExchangeTypes.TOPIC),
            key = {"#.red","*.k"} //topic使用方式 *表示一个字符  ，#表示0个或多个字符
    ))
    public void ConsumerTopicAmqp1Test(String msg) {
        System.out.println("topi接收1"+msg);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "simple.queue2"),
            exchange = @Exchange(name = "exchange.topic",type = ExchangeTypes.TOPIC),
            key = {"red.#","k.*"}
    ))
    public void ConsumerTopicAmqp2Test(String msg) {
        System.out.println("topi接收2"+msg);
    }
}
